package com.qianfeng.smartmetting.config;

import com.alibaba.fastjson2.JSON;
import com.qianfeng.smartmetting.util.CommonResult;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.AuthenticationEntryPoint;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;


//请求未认证
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse
            , AuthenticationException e) throws IOException, ServletException {
        Map  map = CommonResult.error(-1,"用户未认证");
        String result = JSON.toJSONString(map);

        httpServletResponse.setContentType("application/json;charset=utf-8");

        httpServletResponse.getWriter().write(result);
    }


}
